<?php

namespace frontend\controllers;

use Yii;
use common\models\articles\Articles;
use common\models\articles\articlesSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\data\Pagination;

/**
 * ArticlesController implements the CRUD actions for Articles model.
 */
class ArticlesController extends Controller
{

    /**
     * Lists all Articles models.
     * @return mixed
     */
    public function actionIndex()
    {
		$id = Yii::$app->request->get()["id"];
		$info = Articles::find()->where(['id' => $id])->asArray()->one();
		$title = $info['title'];
		$content = $info['content'];
		$soucer = "北京万虎网络有限公司";
		$date = date("Y-m-d",$info['created_at']);
		return $this->render('index',['title' => $title,'content' => $content,'soucer' => $soucer,'date' => $date]);
    }
	
	public function actionList(){

		$cid = Yii::$app->request->get()["cid"];
		$artice_model = Articles::find()->where(['category_id' => $cid]);
		$pages = new Pagination(['totalCount'=>$artice_model->count(), 'pageSize'=>1]);	//分页
		//动态读取内容
		$datas = $artice_model->offset($pages->offset)
		->limit($pages->limit)
		->orderby('id DESC')
		->all();
		return $this->render('list',['list' => $datas,'pages' => $pages]);
	}

    /**
     * Finds the Articles model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Articles the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Articles::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
